package com.company.netease2020;

import java.util.Scanner;

public class Test202004 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int p = sc.nextInt();
            int q = sc.nextInt();
            int sub = b - a;
            long temp = p;

            int res = 1;
            while (sub > temp ){
                temp *= q;
                res++;
            }
            System.out.println(res);
        }
    }
}
